home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Graphics / SPD / Sources / lib.h < prev    next >
Encoding:
Text File  |  1994-10-28  |  18.7 KB  |  549 lines  |  [TEXT/R*ch]

  1. /*
  2.  * lib.h - library definitions
  3.  *
  4.  * Author:  Eric Haines, 3D/Eye, Inc.
  5.  *
  6.  * Modified: 1 October 1992
  7.  *           Alexander R. Enzmann
  8.  *           I made quite a few changes in order to support multiple raytracers,
  9.  *           with the hopes that this library would become even more useful than
  10.  *           it already is.
  11.  *
  12.  * Modified: 17 Jan 1993
  13.  *           Eduard [esp] Schwan
  14.  *           Removed unused local variables & returned value in lib_output_color
  15.  *
  16.  * Modified: 17 Mar 1993
  17.  *           Eduard [esp] Schwan
  18.  *           Changed POV-Ray refs to OUTPUT_POVRAY_10 & OUTPUT_POVRAY_20
  19.  *           Changed POV-Ray 1.5 refs to 2.0
  20.  *           Passed bg_color to display routines
  21.  *             (unfortunate side-effect is you should now call
  22.  *             lib_output_background_color BEFORE lib_output_viewpoint.
  23.  *             This may not be the best approach - please review!)
  24.  *           Added OUTPUT_RAWTRI output, for creating Raw output for Raw2POV.
  25.  *           Added separator comment lines between fns for readability
  26.  *
  27.  * Modified: 30 Mar 1993
  28.  *           Eduard [esp] Schwan
  29.  *           Made poly static arrays dynamic
  30.  *           Created lib_init/lib_shutdown routines
  31.  *           Removed unused local variables
  32.  *           Added creation of enclosing sphere of bg color for POV-Ray
  33.  *
  34.  * Modified: 12 April 1993
  35.  *           Alexander R. Enzmann
  36.  *           Updated to include Eric Haines' version 3.1 SPD data types
  37.  *
  38.  * Modified: 16 April 1993
  39.  *           Eduard [esp] Schwan
  40.  *           Sprinkled MULTITASK macros in loops to let cooperative
  41.  *           multitasking OS systems (Macs) breathe, and added a
  42.  *           string version # & accessor routine for reporting.
  43.  *
  44.  * Modified: 27 July 1993
  45.  *           David Hook
  46.  *           Added converter for "art" ray tracer.
  47.  *
  48.  * Modified: 5 August 1993
  49.  *           Eduard [esp] Schwan
  50.  *           Fixed filename bug in lib_get_opts,
  51.  *           cleaned up Mac #pragma statements, made USAGE a fn,
  52.  *           added '/' as command line switch prefix for MSDOS dudes.
  53.  *           Added POV 2.0 cone and disc primitive syntax, removed
  54.  *           redundant "object { }" wrapper around POV 2.0 objects,
  55.  *           added POV 2.0 "background {}" statement.  Also cleaned
  56.  *           up indenting by adding tab_() routines.  Added A Enzmann's
  57.  *           fixes to the POV 1.0 cylinder/cone routines.
  58.  *
  59.  * Modified: 31 August 1993
  60.  *           Eric Haines
  61.  *           Minor syntax things (hey, I like 4 space indents).
  62.  *
  63.  * Modified: 5 September 1993
  64.  *           Antonio Costa
  65.  *           Changed EPSILON to EPSILON2 in several places
  66.  *           Removed incorrect statement in lib_output_polygon_cylcone()
  67.  *           Added missing break statement to RTrace related code (in
  68.  *           old line 757)
  69.  *
  70.  * Modified: 6 September 1993
  71.  *           Eric Haines
  72.  *           Created standardized lib_open/lib_close functions
  73.  *           Renamed lib_initialize/lib_shutdown to lib_storage_*
  74.  *
  75.  * Modified: 8 September 1993
  76.  *           Antonio Costa
  77.  *           Added global gRT_orig_format to make lib_open/lib_close work!
  78.  *
  79.  * Modified: 16 October 1993
  80.  *           Eduard [esp] Schwan
  81.  *           Added  show_usage prototype so shells.c can call it, broke lib.c
  82.  *           into several smaller sub-libraries for small-model compiles.
  83.  *
  84.  * Modified  19 January 1994
  85.  *           Philipp Slusallek
  86.  *           Added RIB file output
  87.  *
  88.  * Modified: 3 May 1994
  89.  *         Eric Haines
  90.  *         Split lib_get_opts to lib_gen_get_opts and lib_read_get_opts,
  91.  *         since the read*.c programs are functionally different than the
  92.  *         database generators.  Also split show_usage.
  93.  *
  94.  * Modified: 6 May 1994
  95.  *           Eduard [esp] Schwan
  96.  *           Broke libprm.c into even smaller sub-libraries for small-model
  97.  *           Mac compiles, since the new RIB code pushed us over again.
  98.  *           So libprm.c is now libpr1.c and libpr2.c.  Also took a guess and
  99.  *           added OUTPUT_RIB to the list in lib_output_comment() in libpr1.c.
  100.  *
  101.  * Modified: 13 May 1994
  102.  *           Eric Haines
  103.  *           Various changes from esp added, and put in primitive DXF output.
  104.  *           Named version 3.3 now to differentiate from DXF-less output
  105.  *           version Eduard is distributing.
  106.  */
  107.  
  108.  
  109. #ifndef LIB_H
  110. #define LIB_H
  111.  
  112. #include "def.h"
  113. #include "libvec.h"
  114.  
  115. #if __cplusplus
  116. extern "C" {
  117. #endif
  118.  
  119. /* The version of this Library, see lib_get_version_str() */
  120. #define LIB_VERSION    "3.4"
  121.  
  122. /* Raytracers supported by this package (default OUTPUT_POVRAY): */
  123.  
  124. /* Note: any new renderers should be added between OUTPUT_VIDEO and
  125.    OUTPUT_DELAYED.  These two values are used as a range check that a known
  126.    renderer has been selected in "lib_set_raytracer" */
  127. #define OUTPUT_VIDEO      0 /* Output direct to the screen (sys dependent) */
  128. #define OUTPUT_NFF        1 /* MTV                                         */
  129. #define OUTPUT_POVRAY_10  2 /* POV-Ray 1.0                                 */
  130. #define OUTPUT_POLYRAY    3 /* Polyray v1.4, v1.5                          */
  131. #define OUTPUT_VIVID      4 /* Vivid 2.0                                   */
  132. #define OUTPUT_QRT        5 /* QRT 1.5                                     */
  133. #define OUTPUT_RAYSHADE   6 /* Rayshade                                    */
  134. #define OUTPUT_POVRAY_20  7 /* POV-Ray 2.0 (format is subject to change)   */
  135. #define OUTPUT_RTRACE     8 /* RTrace 8.0.0                                */
  136. #define OUTPUT_PLG        9 /* PLG format for use with "rend386"           */
  137. #define OUTPUT_RAWTRI    10 /* Raw triangle output                         */
  138. #define OUTPUT_ART       11 /* Art 2.3                                     */
  139. #define OUTPUT_RIB       12 /* RenderMan RIB format                        */
  140. #define OUTPUT_DXF       13 /* Autodesk DXF format                         */
  141. #define OUTPUT_OBJ       14 /* Wavefront OBJ format                        */
  142. #define OUTPUT_DELAYED   15 /* Needed for RTRACE/PLG output.
  143.                    When this is used, all definitions will be
  144.                    stored rather than immediately dumped.  When
  145.                    all definitions are complete, use the call
  146.                    "lib_flush_definitions" to spit them all out. */
  147.  
  148. /* Default setting of output RT type - change to your favorite & recompile */
  149. #define OUTPUT_RT_DEFAULT   OUTPUT_NFF
  150.  
  151. /* Sets raw triangle output format to include texture name */
  152. #define RAWTRI_WITH_TEXTURES    0    /* set to 1 to include texture */
  153.  
  154. #define OUTPUT_RESOLUTION       4       /* default amount of polygonalization */
  155.  
  156.  
  157. /* ========== don't mess from here on down ============================= */
  158.  
  159. /* Output library definitions */
  160. #define OUTPUT_CURVES           0       /* true curve output */
  161. #define OUTPUT_PATCHES          1       /* polygonal patches output */
  162.  
  163. /* polygon stuff for libply.c and lib.c */
  164. #define VBUFFER_SIZE    1024
  165. #define POLYEND_SIZE    512
  166.  
  167. /*-----------------------------------------------------------------*/
  168. /* The following type definitions are used to build & store the database
  169.    internally.  For some renderers, you need to build the data file according
  170.    to a particular scheme (notably RTrace).  These data types are used to
  171.    hold the objects, lights, etc. until it is time to build the file.  */
  172.  
  173. /* Type definition for holding a light */
  174. typedef struct light_struct *light_ptr;
  175. struct light_struct {
  176.    COORD4 center_pt;
  177.    light_ptr next;
  178.    };
  179.  
  180. /* Type definition for holding a surface declaration */
  181. typedef struct surface_struct *surface_ptr;
  182. struct surface_struct {
  183.    char *surf_name;
  184.    unsigned int surf_index;
  185.    COORD3 color;
  186.    double ka, kd, ks, shine, ang, kt, ior;
  187.    surface_ptr next;
  188.    };
  189.  
  190. /* Diagonally opposite corners of a box */
  191. struct box_struct {
  192.    COORD3 point1, point2;
  193.    };
  194.  
  195. /* Base point/radius and Apex point/radius */
  196. struct cone_struct {
  197.    COORD4 apex_pt, base_pt;
  198.    };
  199.  
  200. /* Center, normal, inner, and outer radii of a annulus */
  201. struct disc_struct {
  202.    COORD3 center, normal;
  203.    double iradius, oradius;
  204.    };
  205.  
  206. /* 2D gridded data for a height field.  Limited support for this thing... */
  207. struct height_struct {
  208.    char *filename;
  209.    float **data;
  210.    unsigned int width, height;
  211.    float x0, x1, y0, y1, z0, z1;
  212.    };
  213.  
  214. /* Polygon - # of vertices and the 3D coordinates of the vertices themselves */
  215. struct polygon_struct {
  216.    unsigned int tot_vert;
  217.    COORD3 *vert;
  218.    };
  219.  
  220. /* Smooth patch.  Vertices and normals associated with them. */
  221. struct polypatch_struct {
  222.    unsigned int tot_vert;
  223.    COORD3 *vert, *norm;
  224.    };
  225.  
  226. /* Center/radius of a sphere */
  227. struct sphere_struct {
  228.    COORD4 center_pt;
  229.    };
  230.  
  231. /* Center, axis lengths, and exponents of a superquadric */
  232. struct superq_struct {
  233.    COORD3 center_pt;
  234.    double a1, a2, a3, n, e;
  235.    };
  236.  
  237. /* Center, direction of axis of symmetry, inner, and outer radii of a torus */
  238. struct torus_struct {
  239.    COORD3 center, normal;
  240.    double iradius, oradius;
  241.    };
  242.  
  243. /* Standard viewpoint stuff */
  244. typedef struct {
  245.    COORD3 from, at, up;
  246.    double angle, aspect, hither, dist;
  247.    int resx, resy;
  248.    MATRIX tx;
  249.    } viewpoint;
  250.  
  251. /*-----------------------------------------------------------------*/
  252. #define BOX_OBJ       1
  253. #define CONE_OBJ      2
  254. #define DISC_OBJ      3
  255. #define HEIGHT_OBJ    4
  256. #define POLYGON_OBJ   5
  257. #define POLYPATCH_OBJ 6
  258. #define SPHERE_OBJ    7
  259. #define SUPERQ_OBJ    8
  260. #define TORUS_OBJ     9
  261.  
  262. /* Union of all the object types */
  263. typedef struct object_struct *object_ptr;
  264. struct object_struct {
  265.    unsigned int object_type;  /* Identify what kind of object */
  266.    unsigned int curve_format; /* Output as surface or as polygons? */
  267.    unsigned int surf_index;   /* Which surface was associated with this object? */
  268.    union {
  269.       struct box_struct       box;
  270.       struct cone_struct      cone;
  271.       struct disc_struct      disc;
  272.       struct height_struct    height;
  273.       struct polygon_struct   polygon;
  274.       struct polypatch_struct polypatch;
  275.       struct sphere_struct    sphere;
  276.       struct superq_struct    superq;
  277.       struct torus_struct     torus;
  278.       } object_data;
  279.    object_ptr next_object;
  280.    };
  281.  
  282. /*-----------------------------------------------------------------*/
  283. /* Global variables - lib.h */
  284. /*-----------------------------------------------------------------*/
  285. #ifdef OUTPUT_TO_FILE
  286. extern FILE * gStdout_file;
  287. #else
  288. #define gStdout_file stdout
  289. #endif /* OUTPUT_TO_FILE */
  290.  
  291. /*
  292. Here are some local variables that are used to control things like
  293. the current output file, current texture, ...
  294. */
  295. extern FILE *gOutfile;
  296. extern char *gTexture_name;
  297. extern int  gTexture_count;
  298. extern double gTexture_ior;
  299. extern int  gRT_out_format;
  300. extern int  gRT_orig_format;
  301. extern int  gU_resolution;
  302. extern int  gV_resolution;
  303. extern COORD3 gBkgnd_color;
  304. extern COORD3 gFgnd_color;
  305. extern double gView_bounds[2][3];
  306. extern int gView_init_flag;
  307. extern char *gLib_version_str;
  308.  
  309. extern surface_ptr gLib_surfaces;
  310. extern object_ptr gLib_objects;
  311. extern light_ptr gLib_lights;
  312. extern viewpoint gViewpoint;
  313.  
  314. /* Globals for tracking indentation level of output file */
  315. extern int    gTab_width;
  316. extern int    gTab_level;
  317.  
  318. /*-----------------------------------------------------------------*/
  319. /* Global variables - libply.h */
  320. /*-----------------------------------------------------------------*/
  321. /* Polygon stack for making PLG files */
  322. extern object_ptr gPolygon_stack;
  323. extern unsigned long gVertex_count; /* Vertex coordinates */
  324. extern unsigned long gNormal_count; /* Vertex normals */
  325.  
  326. /* Storage for polygon indices */
  327. extern unsigned int *gPoly_vbuffer;
  328. extern int *gPoly_end;
  329.  
  330. /* Globals to determine which axes can be used to split the polygon */
  331. extern int gPoly_Axis1;
  332. extern int gPoly_Axis2;
  333.  
  334.  
  335. /*-----------------------------------------------------------------*/
  336. /* Function Prototypes */
  337. /*-----------------------------------------------------------------*/
  338.  
  339. /*==== Prototypes from libinf.c ====*/
  340.  
  341. void    tab_indent PARAMS((void));
  342. void    tab_inc PARAMS((void));
  343. void    tab_dec PARAMS((void));
  344. char *    lib_get_version_str PARAMS((void));
  345. void    lib_set_output_file PARAMS((FILE *new_outfile));
  346. void    lib_set_default_texture PARAMS((char *default_texture));
  347. void    lib_set_raytracer PARAMS((int default_tracer));
  348. void    lib_set_polygonalization PARAMS((int u_steps, int v_steps));
  349. void    lookup_surface_stats PARAMS((int index, int *tcount, double *tior));
  350.  
  351.  
  352. /*==== Prototypes from libpr1.c ====*/
  353.  
  354. void lib_output_comment PARAMS((char *comment));
  355.  
  356. void lib_output_vector PARAMS((double x, double y, double z));
  357.  
  358. void axis_to_z PARAMS((COORD3 axis, double *xang, double *yang));
  359.  
  360. /*
  361.  * Output viewpoint location.  The parameters are:
  362.  *   From:   The eye location.
  363.  *   At:     A position to be at the center of the image.  A.k.a. "lookat"
  364.  *   Up:     A vector defining which direction is up.
  365.  *   Fov:    Vertical field of view of the camera
  366.  *   Aspect: Aspect ratio of horizontal fov to vertical fov
  367.  *   Hither: Minimum distance to any ray-surface intersection
  368.  *   Resx:   X resolution of resulting image
  369.  *   Resy:   Y resolution of resulting image
  370.  *
  371.  * For all databases some viewing parameters are always the same:
  372.  *
  373.  *   Viewing angle is defined as from the center of top pixel row to bottom
  374.  *     pixel row and left column to right column.
  375.  *   Yon is "at infinity."
  376.  */
  377. void lib_output_viewpoint PARAMS((COORD3 from, COORD3 at, COORD3 up,
  378.                   double fov_angle, double aspect_ratio,
  379.                   double hither, int resx, int resy));
  380.  
  381.  
  382. /*
  383.  * Output light.  A light is defined by position.  All lights have the same
  384.  * intensity.
  385.  *
  386.  */
  387. void lib_output_light PARAMS((COORD4 center_pt));
  388.  
  389.  
  390. /*-----------------------------------------------------------------*/
  391. /*
  392.  * Output background color.  A color is simply RGB (monitor dependent, but
  393.  * that's life).
  394.  * NOTE: Do this BEFORE lib_output_viewpoint(), for display_init()
  395.  */
  396. void lib_output_background_color PARAMS((COORD3 color));
  397.  
  398.  
  399. /*-----------------------------------------------------------------*/
  400. /*
  401.  * Output color and shading parameters for all following objects
  402.  *
  403.  * For POV-Ray and Polyray, a character string will be returned that
  404.  * identified this texture.  The default texture will be updated with
  405.  * the name generated by this function.
  406.  *
  407.  * Meaning of the color and shading parameters:
  408.  *    name   = name that this surface can be referenced by...
  409.  *    color  = surface color
  410.  *    ka     = ambient component
  411.  *    kd     = diffuse component
  412.  *    ks     = amount contributed from the reflected direction
  413.  *    shine  = contribution from specular highlights
  414.  *    ang    = angle at which the specular highlight falls to 50% of maximum
  415.  *    t      = amount from the refracted direction
  416.  *    i_of_r = index of refraction of the surface
  417.  *
  418.  */
  419. char *lib_output_color PARAMS((char *name, COORD3 color, double ka,
  420.                    double kd, double ks, double shine,
  421.                    double ang, double kt, double i_of_r));
  422.  
  423.  
  424.  
  425. /*==== Prototypes from libpr2.c ====*/
  426.  
  427. /*-----------------------------------------------------------------*/
  428. /*
  429.  * Output cylinder or cone.  A cylinder is defined as having a radius and an
  430.  * axis defined by two points, which also define the top and bottom edge of the
  431.  * cylinder.  A cone is defined similarly, the difference being that the apex
  432.  * and base radii are different.  The apex radius is defined as being smaller
  433.  * than the base radius.  Note that the surface exists without endcaps.
  434.  *
  435.  * If format=OUTPUT_CURVES, output the cylinder/cone in format:
  436.  *     "c"
  437.  *     base.x base.y base.z base_radius
  438.  *     apex.x apex.y apex.z apex_radius
  439.  *
  440.  * If the format=OUTPUT_POLYGONS, the surface is polygonalized and output.
  441.  * (4*OUTPUT_RESOLUTION) polygons are output as rectangles by
  442.  * lib_output_polypatch.
  443.  */
  444. void lib_output_cylcone PARAMS((COORD4 base_pt, COORD4 apex_pt,
  445.                 int curve_format));
  446.  
  447.  
  448. /*-----------------------------------------------------------------*/
  449. void lib_output_disc PARAMS((COORD3 center, COORD3 normal,
  450.                  double iradius, double oradius,
  451.                  int curve_format));
  452.  
  453.  
  454. /*-----------------------------------------------------------------*/
  455. /*
  456.  * Output sphere.  A sphere is defined by a radius and center position.
  457.  *
  458.  * If format=OUTPUT_CURVES, output the sphere in format:
  459.  *     "s" center.x center.y center.z radius
  460.  *
  461.  * If the format=OUTPUT_POLYGONS, the sphere is polygonalized and output.
  462.  * The sphere is polygonalized by splitting it into 6 faces (of a cube
  463.  * projected onto the sphere) and dividing these faces by equally spaced
  464.  * great circles.  OUTPUT_RESOLUTION affects the number of great circles.
  465.  * (6*2*u_resolution*v_resolution) polygons are output as triangles
  466.  * using lib_output_polypatch.
  467.  */
  468. void lib_output_sphere PARAMS((COORD4 center_pt, int curve_format));
  469.  
  470.  
  471.  
  472. /*-----------------------------------------------------------------*/
  473. /* Output box.  A box is defined by a diagonally opposite corners. */
  474. void lib_output_box PARAMS((COORD3 point1, COORD3 point2));
  475.  
  476.  
  477. /*-----------------------------------------------------------------*/
  478. void lib_output_sq_sphere PARAMS((COORD4 center_pt, double a1, double a2,
  479.                   double a3, double n, double e));
  480.  
  481.  
  482. /*==== Prototypes from libpr3.c ====*/
  483.  
  484. /*-----------------------------------------------------------------*/
  485. void lib_output_height PARAMS((char *, float **, unsigned int, unsigned int,
  486.                    double, double, double, double, double, double));
  487.  
  488.  
  489. /*-----------------------------------------------------------------*/
  490. void lib_output_torus PARAMS((COORD3 center, COORD3 normal,
  491.                   double iradius, double oradius,
  492.                   int curve_format));
  493.  
  494.  
  495. /*==== Prototypes from libini.c ====*/
  496.  
  497. int        lib_open PARAMS((int raytracer_format, char *filename));
  498.  
  499. void    lib_close PARAMS((void));
  500.  
  501. void    lib_storage_initialize PARAMS((void));
  502.  
  503. void    lib_storage_shutdown PARAMS((void));
  504.  
  505. void    show_gen_usage PARAMS((void));
  506. void    show_read_usage PARAMS((void));
  507.  
  508. int        lib_gen_get_opts PARAMS((int argc, char *argv[],
  509.             int *p_size, int *p_rdr, int *p_curve));
  510. int        lib_read_get_opts PARAMS((int argc, char *argv[],
  511.             int *p_rdr, int *p_curve, char *p_infname));
  512.  
  513. void    lib_clear_database PARAMS((void));
  514. void    lib_flush_definitions PARAMS((void));
  515.  
  516.  
  517. /*==== Prototypes from libply.c ====*/
  518.  
  519. void    lib_output_polygon_cylcone PARAMS((COORD4 base_pt, COORD4 apex_pt));
  520. void    lib_output_polygon_disc PARAMS((COORD3 center, COORD3 normal,
  521.                             double iradius, double oradius));
  522. void    lib_output_polygon_sphere PARAMS((COORD4 center_pt));
  523. void    lib_output_polygon_height PARAMS((unsigned int height, unsigned int width, float **data,
  524.                             double x0, double x1,
  525.                             double y0, double y1,
  526.                             double z0, double z1));
  527. void    lib_output_polygon_torus PARAMS((COORD3 center, COORD3 normal,
  528.                             double iradius, double oradius));
  529. void    lib_output_polygon_box PARAMS((COORD3 p1, COORD3 p2));
  530. void    lib_output_polygon PARAMS((int tot_vert, COORD3 vert[]));
  531. void    lib_output_polypatch PARAMS((int tot_vert, COORD3 vert[], COORD3 norm[]));
  532.  
  533.  
  534. /*==== Prototypes from libdmp.c ====*/
  535.  
  536. void    dump_plg_file PARAMS((void));
  537. void    dump_obj_file PARAMS((void));
  538. void    dump_all_objects PARAMS((void));
  539. void    dump_reorder_surfaces PARAMS((void));
  540. void    dump_all_lights PARAMS((void));
  541. void    dump_all_surfaces PARAMS((void));
  542.  
  543. #if __cplusplus
  544. }
  545. #endif
  546.  
  547. #endif /* LIB_H */
  548.  
  549.